from flask import Flask,jsonify
from flask.views import View

app = Flask(__name__)

#需求：返回的结果必须是json数据

class BaseView(View):

    def get_data(self):
        pass

    def dispatch_request(self):
        return jsonify(self.get_data())

class JsonView(BaseView):

    def get_data(self):
        return {'uname':'吕布','age':30}

class Json2View(BaseView):

    def get_data(self):
        return [
                {'name':'sxt','lua':'python'},
                {'name':'百战','lua':'java'}
        ]

app.add_url_rule('/json/',view_func=JsonView.as_view('json'))
app.add_url_rule('/json2/',view_func=Json2View.as_view('json2'))

if __name__ == '__main__':
    app.run(debug=True)